package kyssion.leetcode.num151_200;

public class code172_阶乘后的0 {
    public static void main(String[] args) {
        long one = System.currentTimeMillis();
        System.out.println(new code172_阶乘后的0().trailingZeroes(1808548329));
        System.out.println(new code172_阶乘后的0().trailingZeroes2(1808548329));

        long two = System.currentTimeMillis();
        System.out.println(two - one);
    }

    public int trailingZeroes(int n) {
        int f = 0;
        for (int a = 1; a <= n; a++) {
            f += get5(a);
        }
        return f;
    }

    public int get5(int n) {
        int index = 0;
        while (n % 5 == 0) {
            n = n / 5;
            index++;
        }
        return index;
    }

    /**
     * 找5 进入思维陷阱了  其实就是找一个0 两个0 三个0  然后迭代加就行了
     *
     * @param n
     * @return
     */
    public int trailingZeroes2(int n) {
        long speed = 5;
        int item = 0;
        while (speed <= n) {
            item += n / speed;
            speed = speed * 5;
        }
        return item;
    }

}
